from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-25 14:03:46.516970
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 25, Dec, 2021
Time: 14:03:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6179
Nobs: 516.000 HQIC: -48.0683
Log likelihood: 5976.93 FPE: 9.95868e-22
AIC: -48.3585 Det(Omega_mle): 8.37872e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357513 0.077706 4.601 0.000
L1.Burgenland 0.100119 0.043543 2.299 0.021
L1.Kärnten -0.115331 0.022475 -5.132 0.000
L1.Niederösterreich 0.180283 0.090497 1.992 0.046
L1.Oberösterreich 0.115243 0.090554 1.273 0.203
L1.Salzburg 0.283499 0.046910 6.044 0.000
L1.Steiermark 0.022421 0.060523 0.370 0.711
L1.Tirol 0.109181 0.048843 2.235 0.025
L1.Vorarlberg -0.081396 0.043129 -1.887 0.059
L1.Wien 0.034552 0.082208 0.420 0.674
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.017396 0.171442 0.101 0.919
L1.Burgenland -0.048112 0.096070 -0.501 0.617
L1.Kärnten 0.035271 0.049585 0.711 0.477
L1.Niederösterreich -0.208509 0.199663 -1.044 0.296
L1.Oberösterreich 0.454817 0.199788 2.276 0.023
L1.Salzburg 0.313778 0.103496 3.032 0.002
L1.Steiermark 0.108426 0.133532 0.812 0.417
L1.Tirol 0.316417 0.107762 2.936 0.003
L1.Vorarlberg 0.010827 0.095156 0.114 0.909
L1.Wien 0.009782 0.181375 0.054 0.957
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220524 0.039600 5.569 0.000
L1.Burgenland 0.092384 0.022190 4.163 0.000
L1.Kärnten -0.005381 0.011453 -0.470 0.638
L1.Niederösterreich 0.224886 0.046118 4.876 0.000
L1.Oberösterreich 0.163592 0.046147 3.545 0.000
L1.Salzburg 0.037543 0.023906 1.570 0.116
L1.Steiermark 0.030067 0.030843 0.975 0.330
L1.Tirol 0.078519 0.024891 3.155 0.002
L1.Vorarlberg 0.055557 0.021979 2.528 0.011
L1.Wien 0.103435 0.041894 2.469 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153520 0.039162 3.920 0.000
L1.Burgenland 0.043211 0.021945 1.969 0.049
L1.Kärnten -0.013159 0.011327 -1.162 0.245
L1.Niederösterreich 0.155772 0.045609 3.415 0.001
L1.Oberösterreich 0.344009 0.045638 7.538 0.000
L1.Salzburg 0.099913 0.023642 4.226 0.000
L1.Steiermark 0.112183 0.030503 3.678 0.000
L1.Tirol 0.089539 0.024616 3.637 0.000
L1.Vorarlberg 0.054735 0.021737 2.518 0.012
L1.Wien -0.040780 0.041431 -0.984 0.325
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150592 0.074125 2.032 0.042
L1.Burgenland -0.034646 0.041537 -0.834 0.404
L1.Kärnten -0.036519 0.021439 -1.703 0.088
L1.Niederösterreich 0.131206 0.086326 1.520 0.129
L1.Oberösterreich 0.175359 0.086380 2.030 0.042
L1.Salzburg 0.256838 0.044748 5.740 0.000
L1.Steiermark 0.081225 0.057734 1.407 0.159
L1.Tirol 0.134040 0.046592 2.877 0.004
L1.Vorarlberg 0.104745 0.041142 2.546 0.011
L1.Wien 0.039848 0.078419 0.508 0.611
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078223 0.058672 1.333 0.182
L1.Burgenland 0.016441 0.032877 0.500 0.617
L1.Kärnten 0.050874 0.016969 2.998 0.003
L1.Niederösterreich 0.182042 0.068330 2.664 0.008
L1.Oberösterreich 0.329768 0.068373 4.823 0.000
L1.Salzburg 0.051187 0.035419 1.445 0.148
L1.Steiermark -0.004195 0.045698 -0.092 0.927
L1.Tirol 0.127075 0.036879 3.446 0.001
L1.Vorarlberg 0.059467 0.032565 1.826 0.068
L1.Wien 0.110496 0.062071 1.780 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.176038 0.071012 2.479 0.013
L1.Burgenland 0.010511 0.039793 0.264 0.792
L1.Kärnten -0.061002 0.020539 -2.970 0.003
L1.Niederösterreich -0.110675 0.082701 -1.338 0.181
L1.Oberösterreich 0.228088 0.082753 2.756 0.006
L1.Salzburg 0.039969 0.042869 0.932 0.351
L1.Steiermark 0.262338 0.055310 4.743 0.000
L1.Tirol 0.489605 0.044636 10.969 0.000
L1.Vorarlberg 0.070022 0.039414 1.777 0.076
L1.Wien -0.101780 0.075127 -1.355 0.175
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.138296 0.078761 1.756 0.079
L1.Burgenland -0.011668 0.044135 -0.264 0.791
L1.Kärnten 0.062688 0.022780 2.752 0.006
L1.Niederösterreich 0.173587 0.091726 1.892 0.058
L1.Oberösterreich -0.073505 0.091783 -0.801 0.423
L1.Salzburg 0.222300 0.047547 4.675 0.000
L1.Steiermark 0.138841 0.061345 2.263 0.024
L1.Tirol 0.054573 0.049506 1.102 0.270
L1.Vorarlberg 0.141030 0.043715 3.226 0.001
L1.Wien 0.157090 0.083324 1.885 0.059
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.464049 0.043981 10.551 0.000
L1.Burgenland 0.001251 0.024645 0.051 0.960
L1.Kärnten -0.014023 0.012720 -1.102 0.270
L1.Niederösterreich 0.181136 0.051221 3.536 0.000
L1.Oberösterreich 0.242504 0.051253 4.732 0.000
L1.Salzburg 0.021457 0.026550 0.808 0.419
L1.Steiermark -0.007574 0.034256 -0.221 0.825
L1.Tirol 0.074368 0.027645 2.690 0.007
L1.Vorarlberg 0.056334 0.024411 2.308 0.021
L1.Wien -0.017628 0.046529 -0.379 0.705
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.029848 0.092405 0.152861 0.142408 0.069972 0.081618 0.012526 0.210502
Kärnten 0.029848 1.000000 -0.031143 0.134111 0.051979 0.076016 0.454590 -0.078024 0.101163
Niederösterreich 0.092405 -0.031143 1.000000 0.289514 0.105668 0.257415 0.049314 0.148312 0.253037
Oberösterreich 0.152861 0.134111 0.289514 1.000000 0.198927 0.288269 0.153302 0.132754 0.194853
Salzburg 0.142408 0.051979 0.105668 0.198927 1.000000 0.123957 0.059512 0.111717 0.073208
Steiermark 0.069972 0.076016 0.257415 0.288269 0.123957 1.000000 0.131652 0.090805 0.013539
Tirol 0.081618 0.454590 0.049314 0.153302 0.059512 0.131652 1.000000 0.062452 0.126155
Vorarlberg 0.012526 -0.078024 0.148312 0.132754 0.111717 0.090805 0.062452 1.000000 -0.009540
Wien 0.210502 0.101163 0.253037 0.194853 0.073208 0.013539 0.126155 -0.009540 1.000000